<!DOCTYPE html>
<html>

	<head>
		<title>首页</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=0" />
		<meta http-equiv="Pragma" content="no-cache">
		<meta http-equiv="Cache-control" content="no-cache,no-store,must-revalidate">
		<meta http-equiv="Expires" content="0">
		<link rel="stylesheet" type="text/css" href="static/css/common/reset.min.css" />
		<link rel="stylesheet" type="text/css" href="static/css/common/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="static/css/stage_amortize.css?v=1" />
		<link rel="stylesheet" type="text/css" href="static/css/common/swiper.min.css" />
	</head>

	<body>
		<div id="refreshContainer" class="mui-scroll-wrapper">
			<div class="mui-scroll">
				<div class="body_div">
					<div class="kele_header display">
						<div class="div display">
							<img src="static/img/news@2x.png" /><span>|</span>
							<div class="swiper-container swiper-no-swiping">
								<div class="swiper-wrapper">
									<div class="swiper-slide">138****9028 成功申请1500元</div>
									<div class="swiper-slide">155****2584 成功申请10000元</div>
									<div class="swiper-slide">186****3256 成功申请3000元</div>
									<div class="swiper-slide">131****3466 成功申请8000元</div>
									<div class="swiper-slide">150****8512 成功申请1000元</div>
								</div>
							</div>
						</div>
						<div class="gmore"><i></i></div>
					</div>
					<div class="banner">
						<img src="static/img/stage_banner.png" />
					</div>
				</div>
				<div class="main display">
					<!--首页默认显示内容-->
					<div class="limit">
						<p class="title">可借额度(元)</p>
						<div class="moeny">1000~10000</div>
						<p class="server">日利率0.1%</p>
						<button class="getcredits button">获取额度</button>
						<p class="descBottom display">
							<img src="static/img/ic_light.png" style="display: none;" />
							<span>填写资料即可借款</span>
						</p>
					</div>
					<!--订单状态-->
					<div class="state" style="display: none;">
						<ul class="progress-of-borrow"></ul>
					</div>
					<!--审核失败-->
					<div class="audit_failure display" style="display: none;">
						<img src="static/img/pic_pass.png" />
						<p class="error_p1"></p>
						<p class="error_p2"></p>
						<button class="getcredits error">查看详情</button>
					</div>
				</div>
			</div>
		</div>
		<div class="title_menu">.
			<div class="display">
				<i></i>
				<li>
					<a ontouchstart="apply('order/order_history.html')">我的记录</a>
				</li>
				<li>
					<a ontouchstart="apply('user/cert_center.html')">我的资料</a>
				</li>
				<li>
					<a ontouchstart="apply('user/bank_card.html')">银行卡</a>
				</li>
				<li>
					<a ontouchstart="apply('help_center.html')">帮助中心</a>
				</li>
			</div>
		</div>
	</body>
	<script src="static/js/common.js?v=3"></script>
	<script src="static/js/bridge.js"></script>
	<script src="static/js/common/jquery.min.js"></script>
	<script src="static/js/common/swiper.min.js"></script>
	<script src="static/js/common/mui.min.js"></script>
	<script>
		var aUrl = apiDomain();
		var webUrl = webDomain();
		default_display();

		function default_display() {
			var token = getToken();
			if(token) {
				$.ajax({
					type: "post",
					url: aUrl + "/order/loan_current_order",
					data: {
						token: token
					},
					async: true,
					dataType: 'JSON',
					success: function(data) {
						if(data.status == 2000) {
							var obj = data.data;
							if(obj.orderStatus == 0) {
								loan_home();
								return;
							};
							if(obj.orderStatus == 1) {
								$('.limit , .audit_failure').hide();
								$('.state').show();
								var process = obj.loanBeforeList;
								var borrow = '';
								for(var i = 0; i < process.length; i++) {
									borrow += '<li>' +
										'<div class="clearfix">' +
										'<span></span>  ' +
										'<p>' + process[i].event + '</p>' +
										'<p>' + process[i].eventTime + '</p>' +
										'</div>' +
										'<p>' + process[i].eventDescribe + '</p>' +
										'</li>';
								};
								$('.progress-of-borrow').html(borrow);
								return;
							};
							if(obj.orderStatus == 2) {
								$('.limit , .state').hide();
								$('.audit_failure').show();
								$(".error_p1").html(obj.loanBefore.event)
								$(".error_p2").html(obj.loanBefore.eventDescribe);
								$(".error").attr("data-url", obj.url);
								return;
							};
							if(obj.orderStatus == 3) {
								$('.audit_failure , .state , .server').hide();
								$('.limit').show();
								$(".title").html("未结清借款使用中");
								$('.moeny').html(obj.borrowMoney);
								$('.button').attr("data-status", 5);
								$('.button').html("我要还款").attr("data-url", obj.url);
								$(".descBottom").find("span").html("点击我要还款查看详情");
							};
						} else if(data.status == 4002) {
							closeAndOpen(1);
							return;
						}
					}
				});
			} else {
				loan_home();
			}
		}

		function loan_home() {
			$('.audit_failure , .state').hide();
			$('.limit,.server').show();
			var token = getToken();
			$.ajax({
				type: "post",
				url: aUrl + "/order/loan_home",
				data: {
					token: token,
				},
				async: true,
				dataType: 'JSON',
				success: function(data) {
					if(data.status == 2000) {
						var obj = data.data;
						$(".title").html(obj.title);
						$('.moeny').html(obj.amount);
						$('.server').html(obj.dayRate);
						$('.button').attr("data-url", obj.url);
						$('.button').attr("data-status", obj.status);
						if(obj.status == 2) {
							$('.button').html(obj.descMid);
							$(".descBottom").find("img").show();
							$(".descBottom").find("span").html(obj.hint);
							return
						};
						$('.button').html(obj.descBottom);
						$('.descBottom').find("span").html(obj.descMid);
					} else if(data.status == 4002) {
						closeAndOpen(1);
						return;
					}
				}
			});
		};

		$(".button").on('tap', function() {
			var token = getToken();
			if(!token) {
				closeAndOpen(1);
				return;
			};
			var href = $(this).attr("data-url");
			var status = $(this).attr("data-status");
			skipPage(0, href);
			if(status == 0) {
				mui.confirm('认证成功了吗？', '提示', ["是", "否"], function(e) {
					loan_home();
				})
			} else if(status == 1) {
				mui.confirm('银行卡绑定成功了吗？', '提示', ["是", "否"], function(e) {
					loan_home();
				})
			} else if(status == 2) {
				mui.confirm('提单成功了吗？', '提示', ["是", "否"], function(e) {
					default_display();
				})
			} else {
				mui.confirm('还款成功了吗？', '提示', ["是", "否"], function(e) {
					default_display();
				})
			}
		});

		//审核失败
		$(".error").on('tap', function() {
			var token = getToken();
			if(!token) {
				closeAndOpen(1);
				return;
			};
			var url = $(".error").attr("data-url");
			skipPage(0, url);
		});

		//下拉刷新
		mui.init({
			pullRefresh: {
				container: "#refreshContainer",
				down: {
					contentdown: "下拉可以刷新",
					contentover: "释放立即刷新",
					contentrefresh: "正在刷新...",
					callback: function() {
						setTimeout(function() {
							mui('#refreshContainer').pullRefresh().endPulldownToRefresh(false);
							default_display();
						}, 500);
					}
				}
			}
		});

		//显示更多菜单
		$(".gmore").on("tap", function() {
			$(".title_menu").stop().show();
		});
		//隐藏菜单 
		$(".title_menu").on('tap', function() {
			$(this).stop().hide();
		});

		//跳转
		function apply(url) {
			var token = getToken();
			if(!token) {
				closeAndOpen(1);
				return;
			}
			skipPage(0, webUrl + url);
			$(".title_menu").stop().hide();
		};

		//轮播.
		var mySwiper = new Swiper('.swiper-container', {
			direction: 'vertical',
			autoplay: 2000,
			loop: true,
			auto: true
		});

		$('#scroll').scroll({
			scrollY: true, //是否竖向滚动
			bounce: true, //是否启用回弹
			indicators: false
		});
	</script>

</html>